let app = getApp()
let yuming = app.globalData.yuming
var shuzong = []
var shu = []
const request = require('../../config/request');
Page({
  /**
   * 页面的初始数据
   */
  ...request,
  data: {
    yuming: yuming,
    heights: '',
    title: "曝光台",
  
    list: [],
    page: 1,
    gongwu: false,
    status: 0,
    // 搜素
    keywordsone:"",
    start: '开始时间',
    endtime: '结束时间',
    idx:0,
    currtab: 0,
    begintime: '',
    endtimes: '',
    tab: [{
      id: 0,
      title: '未读'
    },
   
    {
      id: 1,
      title: '已读'
    },
  ],
  },

  tab(e) {
    let that = this;
    let index = e.currentTarget.dataset.index;
    if (index == 0) {
      that.setData({
        status: 0
      })
    }
    if (index == 1) {
      that.setData({
        status: 1
      })
    }
    
    that.setData({
      idx: index,
      start: '开始时间',
      begintime: '',
      endtime: '结束时间',
      endtimes: '',
      keywords: ''
    })
  
  },
  // 搜索

  
  keywordsone(e) {
    console.log(e)
    var key = e.detail.value
    this.setData({
      keywordsone: key
    })


    this.getbgtList()
  
  },
  bindkaishi(e) {
    this.setData({
      start: e.detail.value,
      begintime: e.detail.value,
    })
    this.getbgtList()

  },
  bindjieshu(e) {
    if (e.detail.value < this.data.begintime) {
      wx.showToast({
        title: '结束时间不能小于开始时间',
        icon: 'none'
      })
    } else {
      this.setData({
        endtime: e.detail.value,
        endtimes: e.detail.value,
      })
      this.getbgtList()
    }
  },
  chonzghia(){
    this.setData({
      keywordsone: '',
      endtimes: '',
      start: '开始时间',
    endtime: '结束时间',
      begintime:'',
    })
    this.getbgtList()

  },




  getbgtList() {
    var that = this
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    this.myRequest(yuming + 'shop/shop_exposure_list', {
      shopId: wx.getStorageSync('shopId'),
      page: that.data.page,
      keywords:this.data.keywordsone,
      start_time:this.data.begintime,
      end_time:this.data.endtimes
    }, 'POST').then(res => {
      shu = res.data.data
      if (that.data.page != 1) {
        if (shu.length != 10) {
          wx.showToast({
            title: '没有更多数据了~',
            icon: "none"
          })
          that.setData({
            gongwu: true
          })
        }
      }
      that.setData({
        list: shuzong.concat(shu)
      })
    })
  },
  goxiangqing(e){
    console.log(e.currentTarget.dataset.xiangqing);
    let xiangq = e.currentTarget.dataset.xiangqing
    const xiangqing = JSON.stringify(xiangq)
    wx.navigateTo({
      url: '/my_other/bgtxiangqing/bgtxiangqing?xiangqing='+ xiangqing,
    })
  },
  // 查看更多
  lookmore() {
    shuzong = this.data.list
    this.setData({
      page: (this.data.page) + 1
    })
    this.getbgtList();
  },
  backs() {
    wx.navigateBack({
      delta: 1
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5,
      title: options.title
    })
    this.getbgtList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getbgtList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})